from django.db import models
from django.utils import timezone
from account.models import UserRole, NewUser


class Menu(models.Model):
    """
    菜单表
    """
    menu_name = models.CharField(max_length=20)
    page_url = models.CharField(max_length=100)
    parent_id = models.IntegerField(default=0)
    role = models.ManyToManyField(UserRole)
    is_del = models.IntegerField(default=0)

    def __str__(self):
        return self.menu_name


class ClassGrade(models.Model):
    """
    班级表
    """
    classname = models.CharField(max_length=20)
    add_user = models.ForeignKey(NewUser, on_delete=models.DO_NOTHING, related_name='add_user')
    state = models.IntegerField(default=0)
    add_time = models.DateTimeField(default=timezone.now)
    teacher_user = models.ForeignKey(NewUser, on_delete=models.DO_NOTHING, related_name='teacher_user')
    manager_user = models.ForeignKey(NewUser, on_delete=models.DO_NOTHING, related_name='manager_user')
    start_time = models.DateField(null=True)
    end_time = models.DateField(null=True)
    choice = (
        (0, '训练营'),
        (1, '普通班级')
    )
    class_type = models.PositiveSmallIntegerField(choices=choice,default=0)

    def __str__(self):
        return self.classname


class Dorm(models.Model):
    """
    宿舍表
    """
    dorm_name = models.CharField(max_length=20)
    add_user = models.ForeignKey(NewUser, models.DO_NOTHING)
    add_time = models.DateTimeField(default=timezone.now)
    max_stu = models.IntegerField()
    is_del = models.IntegerField(default=0)

    def __str__(self):
        return self.dorm_name


class StuClass(models.Model):
    """
    班级成员表
    """
    grade = models.ForeignKey(ClassGrade, on_delete=models.DO_NOTHING, related_name='grades')
    student = models.ForeignKey(NewUser, on_delete=models.DO_NOTHING, related_name='students')
    keyboarder = models.ForeignKey(NewUser, on_delete=models.DO_NOTHING, related_name='keyboarders')
    add_time = models.DateField(auto_now_add=True)


class Subsidy(models.Model):
    """
    财务计划表
    """
    money = models.IntegerField()
    type_chose = ((1, '补贴'), (2, '住宿费'))
    type = models.PositiveSmallIntegerField(default=1, choices=type_chose)
    data_time = models.DateTimeField(auto_now_add=True)
    pay_time = models.DateField()
    student = models.ForeignKey(NewUser, on_delete=models.CASCADE, related_name='subsidys')
    keyboarder = models.ForeignKey(NewUser, on_delete=models.CASCADE, related_name='subsidyes')
